from paraview.simple import *
# To ensure correct image size when batch processing, please search
# for and uncomment the line `# renderView*.ViewSize = [*,*]`

# import the simple module from the paraview
# disable automatic camera reset on 'Show'
paraview.simple._DisableFirstRenderCameraReset()

id="6#N5L7463M20"
n_slots = 6

# create a new 'XML Structured Grid Reader'
target_vts = XMLStructuredGridReader(
    FileName=[f"/home/hpc/program/IDEALS3D/DEAD/AutoDecoder/PSFD/VTK/{id}.vts"])

# get active view
renderView1 = GetActiveViewOrCreate('RenderView')

# show data in view
target_vtsDisplay = Show(target_vts, renderView1)

# create a new 'Iso Volume'
isoVolume1 = IsoVolume(Input=target_vts)

# Properties modified on isoVolume1
isoVolume1.InputScalars = ['POINTS', 'define_marker_theta']
isoVolume1.ThresholdRange = [0.0, 50.0]

# create a new 'Iso Volume'
isoVolume2 = IsoVolume(Input=isoVolume1)

# Properties modified on isoVolume1
isoVolume2.InputScalars = ['POINTS', 'define_marker_rho']
isoVolume2.ThresholdRange = [0.0, 50.0]

max_u = isoVolume2.GetPointDataInformation().GetArray('u').GetRange()[1]
#print("max_u is: " + str(max_u))

# create a new 'Contour'
contour1 = Contour(Input=isoVolume2)

# Properties modified on contour1
contour1.ComputeNormals = 1
contour1.GenerateTriangles = 0

# create a new 'Integrate Variables'
integrateVariables1 = IntegrateVariables(Input=contour1)

burned_web_array = []
burning_surface_area_array = []
data_points_number = 50
web_step_size = max_u/(data_points_number-1)*0.999
for i in range(data_points_number):
    web = i*web_step_size
    contour1.Isosurfaces = [web]
    area_data = integrateVariables1.GetCellDataInformation().GetArray(
        'Area').GetRange()[0]*2*n_slots
    # integrated_filter = paraview.servermanager.Fetch(integrateVariables1)
    # area_data = integrated_filter.GetCellData().GetArray('Area').GetValue(0)
    burned_web_array.append(web)
    burning_surface_area_array.append(area_data)